package com.csw.springcloudApp.springcloudAppInfo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.csw.springcloudApp.springcloudAppInfo.dao.IntoDao;
import com.csw.springcloudApp.springcloudAppInfo.entity.Product_info;
import com.csw.springcloudApp.springcloudAppInfo.feign.FeignProductTest;

@RestController
@RequestMapping("info")
@CrossOrigin
public class InfoController {
	@Autowired
	private IntoDao intoDao;
	@Autowired
	private FeignProductTest feignProductTest;

	@RequestMapping("queryall")
	public List<Product_info> queryall() {
		List<Product_info> productInfos = intoDao.selectAll();
		for (Product_info info : productInfos) {
			System.out.println("info]" + info);
		}
		return productInfos;
	}

	@RequestMapping("chuansong")
	public String chuansong(String id) {
		System.out.println("id]" + id);
		return feignProductTest.chuansong(id);
	}

	@RequestMapping("queryProductById")
	public Product_info queryProductById(String id) {
		return intoDao.selectByPrimaryKey(id);
	}

	@RequestMapping("sale")
	public String sale(String id, Integer count) {
		System.out.println("id]" + id);
		System.out.println("count]" + count);
		Product_info product = intoDao.selectByPrimaryKey(id);
		System.out.println("products]" + product);
		product.setProductStock(product.getProductStock() - count);
		product.setSales(product.getSales() + count);
		intoDao.updateByPrimaryKeySelective(product);
		return "success";
	}

}
